#!/bin/bash
#创建测试数据

count=1000000				#每一个key的总条数
count_per_file=100000		#每一个文件的最大数据条数
meta_dir=/home/hadoop/meta			#元数据目录
meta_file=meta.dat					#元数据文件名称
data_dir=/home/hadoop/data			#数据目录
targe_data_file=${data_dir}/data_file	#数据文件名称
keys=("20180531" "20180731" "20180831")	#keys

echo "start date: `date`"
mkdir -p $meta_dir && cd $meta_dir && rm -rf *
mkdir -p $data_dir && cd $data_dir && rm -rf *
echo "make test data ..."

current_number=0
file_number=0
file_name=${targe_data_file}_${file_number}.sql
for key in ${keys[@]};do
	echo "key: $key"
	for (( i = 0; i < $count; i++));do
		if((current_number % count_per_file == 0));then
			((file_number = current_number / count_per_file))
			#echo "current_number: $((current_number + 1))"
			file_name=${targe_data_file}_${file_number}.sql
			echo ${file_name} >> ${meta_dir}/${meta_file}
		fi

		sql="upsert into T_STUDENT values('${key}_${i}','wangpuyang${i}','${i}');"
		echo $sql >> $file_name
		((current_number++))
	done
done

echo "sync $data_dir ..."
dwhdp_prsync.sh $data_dir

hadoop fs -rm -r -f /tmp/phoenix/meta
hadoop fs -mkdir -p /tmp/phoenix/meta
hadoop fs -put $meta_dir/$meta_file /tmp/phoenix/meta
hadoop fs -ls /tmp/phoenix/meta
hadoop jar /home/hadoop/hadoop_test-1.0.jar com.rjhch.dp.mr.phoenix.UpsertMR /tmp/phoenix/meta

echo "end date: `date`"